import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import config from '../common/utils/baseUrl';
import getData_ajax from '../common/utils/getData_ajax';
import { NzMessageService } from 'ng-zorro-antd';
import { NzModalService } from 'ng-zorro-antd';
import * as $ from 'jquery';

@Component({
    selector: 'app-index',
    templateUrl: './index.component.html',
    styleUrls: ['./index.component.scss', '../../assets/css/bootstrap.css', '../../assets/css/font-awesome.css'],
    encapsulation: ViewEncapsulation.Emulated
})
export class IndexComponent implements OnInit {
    // 加载状态
    public isSpinning: any = true;
    // 文章列表数据
    public ariticeData: any = [];
    // 分页查询数据
    public params: any = {
        page: 1,
        maxCount: 5
    };
    // 文章总数
    public totalCount: any = 0;

    constructor(private http: HttpClient, private message: NzMessageService, private modalService: NzModalService) {
    }

    ngOnInit() {
        this.getData();
    }

    /**
     * 初始化数据
     */
    getData() {
        let that = this;
        getData_ajax.getFunc(config.baseUrl + '/articleService/getIndexArticeData', 'post', this.params, function (data) {
                that.ariticeData = data.result;
                that.isSpinning = false;
            },
            function (error) {
                that.modalService.error({
                    nzTitle: '网络错误',
                    nzContent: '请稍后再试...'
                });
                console.log(error);
            });


        this.http.post(config.baseUrl + '/articleService/getArticeData', '')
            .subscribe((data: any) => {
                this.totalCount = data.ariticeTotal;
            });
    }

    /**
     *分页改变
     */
    changePage(page) {
        this.params.page = page;
        this.isSpinning = true;
        this.getData();
    }

}
